package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.RedPacket;
import com.neusoft.service.RedPacketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/RedPacket")
public class RedPacketController {
    @Autowired
    private RedPacketService redPacketService;
    
    @GetMapping("/PacketId")
    public CommonResult<RedPacket> getTheRedPacketByPacketId(RedPacket redPacket) throws Exception {
        return new CommonResult<RedPacket>(200, "success", redPacketService.getTheRedPacketByPacketId(redPacket.getPacketId()));
    }
    
    @PostMapping("/PacketId")
    public CommonResult<Integer> deleteAllRedPacketByPacketId(RedPacket redPacket) throws Exception {
        return new CommonResult<Integer>(200, "success", redPacketService.deleteAllRedPacketByPacketId(redPacket.getPacketId()));
    }

    @GetMapping("/availableRedPacket")
    public CommonResult<List<RedPacket>> getAvailableRedPacketByUserId(RedPacket redPacket) throws Exception {
        return new CommonResult<List<RedPacket>>(200, "success", redPacketService.getAvailableRedPacketByUserId(redPacket.getUserId()));
    }

    @GetMapping("/userId")
    public CommonResult<List<RedPacket>> getRedPacketByUserId(RedPacket redPacket) throws Exception {
        return new CommonResult<List<RedPacket>>(200, "success", redPacketService.getRedPacketByUserId(redPacket.getUserId()));
    }

    @PostMapping("/userId")
    public CommonResult<Integer> insertRedPacket(RedPacket redPacket) throws Exception {
        return new CommonResult<Integer>(200, "success", redPacketService.insertRedPacket(redPacket));
    }
}
